
//
//  SelectView_first.m
//  Sq
//
//  Created by 查传申 on 16/12/6.
//  Copyright © 2016年 mini00010. All rights reserved.
//

#import "SelectView_first.h"

@implementation SelectView_first
-(id)initWithFrame:(CGRect)frame with_arr:(NSArray *)arr{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.4];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(miss)];
        [self addGestureRecognizer:tap];
        UIImageView *view_three = [[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width-38, 0, 18, 10)];
//        view_three.backgroundColor = [UIColor purpleColor];
        view_three.image = [UIImage imageNamed:@"Triangle24.png"];
        
        [self addSubview:view_three];
        
        
        UIView *view_small = [[UIView alloc]initWithFrame:CGRectMake(frame.size.width-151.5, 10, 145, arr.count *44)];
        view_small.clipsToBounds = YES;
        view_small.layer.cornerRadius = 4;
        view_small.backgroundColor = [UIColor whiteColor];
        [self addSubview:view_small];
        
        for (int i = 0 ; i < arr.count; i++) {
            
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button setImage:[UIImage imageNamed:arr[i][@"image"]] forState:UIControlStateNormal];
            button.frame = CGRectMake(20, 44*i+5, view_small.frame.size.width - 15 - 7.5, 35);
            button.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);            button.titleLabel.font = [UIFont systemFontOfSize:16];
            button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            button.tag = 5000+i;
            [button setTitleColor:S_Color_51 forState:UIControlStateNormal];
            [button setTitle:arr[i][@"title"] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(button_Action:) forControlEvents:UIControlEventTouchUpInside];
            [view_small addSubview:button];
            
            UIView *view_line = [[UIView alloc]initWithFrame:CGRectZero];
            view_line.backgroundColor = LMRGBAColor(226, 226, 226, 1);
            [view_small addSubview:view_line];
            view_line.frame = CGRectMake(0, 44*i, view_small.frame.size.width, 1);

        }
    }
    return self;
}
-(void)miss{
    self.hidden = YES;
}
-(void)button_Action:(UIButton *)button{
    NSLog(@"%ld",button.tag);
    [self.delegate renturn_button_num:button.tag-5000];
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
